/**
 * Created by ZHOUSH on 12/18/2015.
 */
var Promise = require('promise');
var csv = require('csv');
var fs = require('fs');
var ptocsv = Promise.denodeify(csv.stringify);
var pcsv = Promise.denodeify(csv.parse);
var pread = Promise.denodeify(fs.readFile);
var pwrite = Promise.denodeify(fs.writeFile);
var toObject = function (name) {
    return pread(name, 'utf-8').then(function (data) {
        return pcsv(data, {
            columns: true
        });
    }, console.log);
};
var toFile = function (obj, name) {
    var _str = '';
    return ptocsv(obj, {
        header: true
    }).then(function (str) {
        _str = str;
        return pwrite(name, str);
    }).then(function () {
        return _str;
    })
};
exports.toObject = toObject;
exports.toFile = toFile;